package com.dp.order.config;

import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @author linzizun
 * @version 1.0
 */
@Configuration
//@EnableSwagger2
public class SwaggerConfig {
    /**
     * 当前文档的标题
     */
    @Value("${swagger.title}")
    private String title;

    /**
     * 当前文档的详细描述
     */
    @Value("${swagger.description}")
    private String description;

    /**
     * 当前文档的版本
     */
    @Value("${swagger.version}")
    private String version;

    @Value("${swagger.contact.name}")
    private String contactName;

    @Value("${swagger.contact.url}")
    private String contactUrl;

    @Value("${swagger.contact.email}")
    private String contactEmail;

    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                // 这里采用包含注解的方式来确定要显示的接口(建议使用这种)，不再使用单路径扫描
                .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                // 项目描述1
                .title(title)
                .description(description)
                .version(version)
                .contact(new Contact(contactName, contactUrl, contactEmail))
                .build();
    }
}